<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<div id="app">
    <button @click="add">加</button>
    <span>{{this.$store.state.counter}}</span>
    <span>{{counter}}</span>
    <span>{{this.$store.getters.totalPrice}}</span>
    <span>{{totalPrice}}</span>
</div>
<script src="./node_modules/vue/dist/vue.js"></script>
<script src="node_modules/vuex/dist/vuex.js"></script>
<script>
    const INCREMENT='increment';
    let store=new Vuex.Store({
        state:{
            counter:88,
        },
        mutations:{
            [INCREMENT]:function (state,payload) {
                state.counter +=payload.num;
            }
        },
        getters:{
            totalPrice:function (state) {
                return state.counter*10;
            }
        }
    })
    let vm = new Vue({
        store,
        computed:{
            ...Vuex.mapState(["counter"]),
            ...Vuex.mapGetters(["totalPrice"]),
        },
        el: "#app",
        data: {
        },
        methods:{
            add:function () {
                this.$store.commit({
                    type:INCREMENT,
                    num:13,
                })
            }
        }
    })
</script>
</body>
</html>
